<?php

class Application_Model_DbTable_Activation extends Zend_Db_Table_Abstract
{

    protected $_name = 'Activation';
    //Add Activation
    public function addActivation($buyer_id,$activation_number) {
        $data = array(
          'buyer_id' => $buyer_id,
          'code' => $activation_number
        );
        $this->insert($data);
    }
    //check whether the activation number already exist or not
    public function checkActivationNumber($number){
      $db=$this->getAdapter();
      $stmt = $db-> query('SELECT code FROM activation');
      $row = $stmt->fetchAll();
      foreach ($row as $user) {
          if($user['code'] == $number){
              return false;
          }
      }
      return true;
      }
      //get username by code
      public function getUsername($code){
          $db=$this->getAdapter();

          $stmt = $db->query("select a.username from buyer a,activation b
                              where b.code='$code' and b.buyer_id=a.buyer_id");
          $row = $stmt->fetchAll();
          return $row[0]['username'];
      }
      //deleting record from activation
      public function deleteActivation($code) {
        $this->delete('code =' . "'".$code."'");
    }


}

